<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xdb="http://orbeon.org/oxf/xml/xmldb" xmlns:xu="http://www.xmldb.org/xupdate">

	<p:processor name="oxf:pipeline">
		<p:input name="config" href="../../session.xpl"/>
		<p:output name="data" id="old_session"/>
	</p:processor>
	<p:processor name="oxf:xslt">
		<p:input name="data" href="#old_session"/>
		<p:output name="data" id="query"/>
		<p:input name="config">
			<xsl:stylesheet version="2.0">
				<xsl:template match="/">
					<xdb:query xsl:version="2.0" collection="/db/portal">
						<xsl:text>xquery version "1.0";</xsl:text>

						<xsl:apply-templates/>
					</xdb:query>
				</xsl:template>
				<xsl:template match="groups">
					<xsl:copy>
						<xsl:apply-templates select="@*"/>
						<group id="gr_0">
							<name>Personal</name>
						</group>
						{for $gr in /groups/group[members/member/@id = '<xsl:value-of select="/session/username"/>'] return 
							element group{
								attribute id{$gr/@id},
								attribute level{$gr/members/member[@id='<xsl:value-of select="/session/username"/>']/@level},
								/groups/group[@id=string($gr/@id)]/name,
								/groups/group[@id=string($gr/@id)]/interface
							}
						}
					</xsl:copy>
				</xsl:template>
				<xsl:template match="@*|node()" priority="-2">
					<xsl:copy>
						<xsl:apply-templates select="@*|node()"/>
					</xsl:copy>
				</xsl:template>
			</xsl:stylesheet>
		</p:input>
	</p:processor>

	<p:processor name="oxf:xmldb-query">
		<p:input name="datasource" href="/config/datasource.xml"/>
		<p:input name="query" href="#query"/>
		<p:output name="data" id="session"/>
	</p:processor>

	<p:processor name="oxf:scope-serializer">
		<p:input name="config">
			<config>
				<key>session</key>
				<scope>session</scope>
				<session-scope>application</session-scope>
			</config>
		</p:input>
		<p:input name="data" href="#session"/>
	</p:processor>

</p:config>